package com.json.controller;

import com.alibaba.fastjson2.JSON;
import com.json.entity.ResponseResult;
import com.json.entity.Student;
import com.json.service.StudentService;
import com.json.service.impl.StudentServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectById")
public class StudentSelectById extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws SecurityException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json:charset=UTF-8");
        Integer id = Integer.parseInt(req.getParameter("id"));
        StudentService studentService = new StudentServiceImpl();
        List<Student> list = studentService.findById(id);
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"查询成功",list)));

    }
}